import request from '@/utils/request';

/**
 *复制、重新发起等操作时获取任务详情
 *
 * @export GET
 * @param {string} id
 * @returns
 */
export async function getActionTaskInfo(id) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/copy`, {
        method: 'GET'
    });
}
/**
 *变更等操作时获取任务详情
 *
 * @export GET
 * @param {string} id
 * @returns
 */
export async function getActionTaskInfoSimple(id) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/change`, {
        method: 'GET'
    });
}
/**
 * 根据taskId获取催办动作前的明细信息
 * @export GET
 * @param {string} id
 * @returns
 */
export async function getPressActionTaskInfo(id) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/urge`, {
        method: 'GET'
    });
}

/**
 * 根据taskId获取变更任务前置状态
 * @export GET
 * @param {string} taskId
 */
export async function getCanUpdateTask(taskId) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/cancel`, {
        method: 'GET'
    });
}

/**
 *复制任务
 */
export async function copyTask(params) {
    const { id } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${id}/actions/copy`, {
        method: 'PUT',
        data: params
    });
}

/**
 *变更任务
 */
export async function updateTask(params) {
    const { id } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${id}`, {
        method: 'PUT',
        data: params
    });
}

/**
 *变更上一级任务前置判断
 */
export async function changeParentTaskCheck(params) {
    const { parentTaskId = '' } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${parentTaskId}/part`, {
        method: 'GET'
    });
}

/**
 *新建子任务
 */
export async function createSubTask(params) {
    const { parentTaskId } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${parentTaskId}/actions/create_subtask`, {
        method: 'PUT',
        data: params
    });
}

/**
 * 根据taskId获取重新发起任务任务前置状态
 * @export GET
 * @param {number} taskId
 */
export async function getRestartInfo(taskId) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/reissues`, {
        method: 'GET'
    });
}

/**
 *重新发起任务
 */
export async function restartTask(params) {
    const { id } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${id}/actions/reissue`, {
        method: 'PUT',
        data: params
    });
}

/**
 * 催办任务
 */
export async function pressTask(params) {
    return request(`/api/oa/v1/work/task/taskinfos/${params.taskId}/actions/urge`, {
        method: 'PUT',
        data: params
    });
}
/**
 * 向审核人催办任务
 */
export async function pressTaskAudit(id) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/actions/urge/audit`, {
        method: 'PUT',
        data: { id }
    });
}
/**
 * 向验收人催办任务
 */
export async function pressTaskAcceptor(id) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/actions/urge/acceptor`, {
        method: 'PUT',
        data: { id }
    });
}
/**
 * 向前置任务执行人催办任务
 */
export async function pressTaskFront(id) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/actions/urge/front-task-executor`, {
        method: 'PUT',
        data: { id }
    });
}
/**
 * 获取任务审核信息
 * @param {number} taskId
 */
export async function getAuditInfo(id) {
    return request(`/api/oa/v1/work/task/audit_tasks/${id}`, {
        method: 'GET'
    });
}
/**
 * 验证任务转已完成操作
 * @param {number} taskId
 */
export async function checkTurnFinish(id) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/actions/check_turn_finish`, {
        method: 'GET'
    });
}
/**
 * 获取任务转已完成信息
 * @param {number} taskId
 */
export async function getTurnFinishInfo(id) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/turn_finish`, {
        method: 'GET'
    });
}
/**
 * 获取我需审核的任务的子任务列表
 * @param {number} taskId
 * @param {number} pageNo
 * @param {number} pageSize
 */
export async function getSubTaskList(params) {
    return request('/api/oa/v1/work/task/audit_tasks/my/sub_audits', {
        method: 'POST',
        data: params
    });
}
/**
 * 审核任务
 * @param {number} taskId  任务id
 * @param {number} taskOperate 需要审核的操作(参照taskConstants中的TaskOperateType)
 * @param {number} auditStatus 审核状态（1=审核通过 2=不通过）
 * @param {number} batchAuditSubTask 批量审核子任务(0=未勾选 1=勾选)(不通过时传)
 * @param {string} auditReason 原因(不通过时传)
 * @param {Array} resourceRelation 附件列表(不通过时传)
 */
export async function auditTask(taskId, taskOperate, auditStatus, batchAuditSubTask, auditReason, resourceRelation) {
    return request('/api/oa/v1/work/task/audit_tasks/actions/audit', {
        method: 'POST',
        data: { taskId, taskOperate, auditStatus, batchAuditSubTask, auditReason, resourceRelation }
    });
}
/**
 * 验收任务
 */
export async function acceptTask(params) {
    return request('/api/oa/v1/work/task/accept_tasks/actions/accept', {
        method: 'POST',
        data: params
    });
}

/**
 * 获取暂停任务信息
 * @param {number} taskId
 */
export async function getPauseInfo(taskId) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/pause`, {
        method: 'GET'
    });
}

/**
 * 暂停任务
 */
export async function pauseTask(params) {
    return request(`/api/oa/v1/work/task/taskinfos/${params.taskId}/actions/pause`, {
        method: 'PUT',
        data: params
    });
}

/**
 * 继续执行任务
 */
export async function continueTask(params) {
    return request(`/api/oa/v1/work/task/taskinfos/${params.taskId}/actions/continue`, {
        method: 'PUT',
        data: params
    });
}

/**
 * 获取任务取消信息
 * @param {number} taskId
 */
export async function getCancelInfo(taskId) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/cancel`, {
        method: 'GET'
    });
}

/**
 * 取消弹窗中进行中的子任务列表
 * @param {number} taskId
 * @param {number} pageNo
 * @param {number} pageSize
 */
export async function getCancelSubTaskList(params) {
    const { taskId } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/cancel/subtask`, {
        method: 'POST',
        data: params
    });
}

/**
 * 获取未完成的子任务列表
 * 取消任务
 */
export async function cancelTask(params) {
    const { taskId } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/actions/cancel`, {
        method: 'PUT',
        data: params
    });
}

/**
 * 获取进行中的子任务列表
 * @param {number} taskId
 * @param {number} pageNo
 * @param {number} pageSize
 */
export async function getUnDoneSubTaskList(params) {
    const { taskId } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/undone_subtasks`, {
        method: 'POST',
        data: params
    });
}

/**
 * 转派任务
 * @param {number} taskId  任务id
 * @param {Array} resourceRelation 附件列表
 * @param {number} executeEmployeeCode 执行人id
 * @param {string} operateReason 原因
 *
 */
export async function transferTask(taskId, resourceRelation, executeEmployeeCode, operateReason) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/actions/redeploy`, {
        method: 'PUT',
        data: { taskId, resourceRelation, executeEmployeeCode, operateReason }
    });
}

/**
 * 转已完成
 * @param {number} taskId  任务id
 * @param {data-time} actualEndTime 实际完成时间
 * @param {number} actualWorkDuration 实际工时（分钟）
 * @param {string} remark 备注说明
 * @param {Array} resourceRelation 附件列表
 *
 */
export async function finishTask(taskId, actualEndTime, actualWorkDuration, remark, resourceRelation) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/actions/turn_finish`, {
        method: 'PUT',
        data: { taskId, actualEndTime, actualWorkDuration, remark, resourceRelation }
    });
}
/*
 * 获取进行中的子任务列表
 * @param {number} taskId
 * @param {number} pageNo
 * @param {number} pageSize
 */
export async function getAfterTaskList(params) {
    const { taskId } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/rear`, {
        method: 'POST',
        data: params
    });
}

/**
 * 获取任务转进行中信息
 * @param {number} taskId
 */
export async function getTurnDoingInfo(taskId) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/turn_on`, {
        method: 'GET'
    });
}

/**
 * 转进行中
 * @param {number} taskId  任务id
 * @param {Array} actualStartTime 实际开始时间
 *
 */
export async function turnDoingTask(params) {
    console.log(params);
    const { taskId } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/actions/turn_on`, {
        method: 'PUT',
        data: params
    });
}

/**
 * 获取任务回退信息
 * @param {number} taskId
 */
export async function getSendBackInfo(taskId) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/send_back`, {
        method: 'GET'
    });
}

/**
 * 退回
 * @param {number} taskId  任务id
 * @param {string} operateReason 原因
 * @param {Array} resourceRelation 附件
 *
 */
export async function sendBackTask(params) {
    const { taskId } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/actions/send_back`, {
        method: 'PUT',
        data: params
    });
}

/**
 * 延期任务
 * @param {number} id  任务id
 * @param {Array} resourceRelation 附件列表
 * @param {number} executeEmployeeCode 执行人id
 * @param {string} operateReason 原因
 * @param {number} delayType 延期类型
 * @param {number} applyPlanEndTime 申请新预估工时
 * @param {string} applyPlanEndTime 新申请截止时间
 *
 */
export async function delayTask(params) {
    const { taskId } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/actions/delay`, {
        method: 'PUT',
        data: params
    });
}

/**
 * 验证任务操作
 * @param {number} taskId
 */
export async function checkOperate(taskId) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/actions/check_operate`, {
        method: 'GET'
    });
}

/**
 * 延期详情
 * @param {number} id  任务id
 *
 */
export async function delayTaskDetail(id) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/delay_details`, {
        method: 'GET'
    });
}

/**
 * 获取任务进度信息
 * @param {number} taskId
 */
export async function getProgressInfo(taskId) {
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/progress`, {
        method: 'GET'
    });
}

/**
 * 填写进度
 * @param {number} taskId  任务id
 * @param {number} resourceRelation 附件列表
 *
 */
export async function updateTaskProgress(params) {
    const { taskId } = params;
    return request(`/api/oa/v1/work/task/taskinfos/${taskId}/actions/progress`, {
        method: 'PUT',
        data: params
    });
}
/**
 * 获取任务操作记录详情信息
 * @param {number} id  任务id
 * @param {number} operateId 操作记录id
 *
 */
export async function getOperateDetails(id, operateId) {
    return request(`/api/oa/v1/work/task/taskinfos/${id}/operate_details/${operateId}`, {
        method: 'GET'
    });
}

// 重评申请
export async function applyReScore(params) {
    return request('/api/oa/v1/work/task/score/actions/launch_rescore_apply', {
        method: 'POST',
        data: params
    });
}

/**
 *获取重估人员列表
 *
 * @export POST
 * @param {object} params
 * @returns
 */
export async function getreestimationemployeelist(params) {
    return request('/api/oa/v1/work/task/estimation/getreestimationemployeelist', {
        method: 'POST',
        data: params
    });
}
